# 线程安全的单例装饰器
from functools import wraps
from threading import RLock

def singleton(cls):
	"线程安全的单例装饰器"
	instances = {}
	locker = RLock()

	@wraps(cls)
	def wrapper(*args, **kwargs):
		print('----wrapper----')
		if cls not in instances:
			print('----not instances----')
			with locker:
				if cls not in instances:
					instances[cls] = cls(*args,**kwargs)
		# print(dir(instances))
		return instances[cls]
	return wrapper

@singleton
class Person(object):
	"""docstring for Person"""
	def __init__(self,name):
		super().__init__()
		self.name = name
		
	def say(self):
		print(f'我的名字是:{self.name}')

p1 = Person('Amy')
p2 = Person('Alice')
p1.say()
p2.say()